package org.fxcontainer.commands
{
	import com.developmentarc.core.actions.commands.AbstractCommand;
	
	import org.fxcontainer.commands.navigation.chain.NavigationURL;
	import org.fxcontainer.commands.navigation.chain.Page;
	
	/**
	 * The navigation command. <br/>
	 * Holds URL to navigate to.
	 * @author Izzet_Mustafayev
	 * 
	 */
	public class URLChangeCommand extends AbstractCommand
	{
		/**
		 * The navigation command type. 
		 */
		static public const URL_CHANGE_CMD:String = "URLChangeCommand";
		
		/**
		 * The navigation URL string representation. 
		 */
		private var _url:String;
		
		/**
		 * The navigation URL object representation. 
		 */
		private var navURL:NavigationURL;
		
		/**
		 * The command constructor.
		 */
		public function URLChangeCommand()
		{
			super(URL_CHANGE_CMD);
			this.navURL = new NavigationURL();
		}
		
		/**
		 * Adds page name to navigate to. 
		 * @param pageName the page name to navigate to
		 * @return the <code>Page</code> object URL. 
		 */
		public function addPage(pageName:String):Page
		{
			this.navURL.addPage(pageName);
			return new Page(this, this.navURL);
		}
		
		/**
		 * Navigation URL getter. 
		 * @return navigation URL
		 */
		public function get url():String
		{
			return this._url;
		}
		
		/**
		 * Dispatches the command through the EventBroker which will
		 * then be passed to any registered action.
		 */
		override public function dispatch():void {
			this._url = this.navURL.toURL();
			super.dispatch();
		}
	}	
}